package com.jiangyao.controller;


import com.jiangyao.common.ApiResult;
import com.jiangyao.common.exception.ServerException;
import com.jiangyao.model.dto.ResumeDTO;
import com.jiangyao.model.dto.ResumeSendDTO;
import com.jiangyao.model.entity.Resume;
import com.jiangyao.model.entity.ResumeSend;
import com.jiangyao.service.ResumeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.dozer.DozerBeanMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 简历 前端控制器
 * </p>
 *
 * @author zhoushuangxiang
 * @since 2020-08-12
 */
@RestController
@RequestMapping("/resume")
@Api(tags = "简历相关接口")
public class ResumeController extends BaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ResumeController.class);

    @Autowired
    private DozerBeanMapper dozerBeanMapper;

    @Autowired
    private ResumeService resumeService;

    /**
     * 创建个人简历
     * @param resumeDTO
     * @return
     */
    @PostMapping("/addResume")
    @ApiOperation(value = "创建个人简历")
    public ApiResult addResume(@Validated({ResumeDTO.Add.class}) @RequestBody ResumeDTO resumeDTO){
        Resume resume = dozerBeanMapper.map(resumeDTO, Resume.class);
        try {
            Resume resume1 = resumeService.addResume(resume);
            return ApiResult.success(resume1);
        } catch (ServerException e) {
            LOGGER.error(resumeDTO.getUserId()+"创建简历失败");
            return ApiResult.error(e.getCode(),e.getMessage());
        }
    }

    /**
     * 获取个人简历
     * @param
     * @return
     */
    @GetMapping("/getResume")
    @ApiOperation(value = "获取个人简历")
    public ApiResult getResume(){
        Resume resume = resumeService.getResume();
        if(resume == null){
            return ApiResult.success("还未创建个人简历");
        }
        return ApiResult.success(resume);
    }
}

